<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>cutSeat 更改订单</title>
	</head>
	<link rel="stylesheet" href="../css/common.css" />
	<style>
		body{
			background: #eeeeee;
		}
		.btnBox{
			height:50px;
			width:100%;
			position:fixed;
			bottom:0;
			left:0;
			text-align:center;
			background:#eeeeee;
		}
		.sure,.cancel{
			height:28px;
			padding:0 35px;
			background:#00aa98;
			border:none;
			border-radius:3px;
			color:white;
			cursor:pointer;
		}
		.cancel{
			margin-left:30px;
			background:#a1a4a9;
		}
		.content p{
			margin:0 auto;
			width:300px;
			text-align-left;
			padding:4px 0;
			height:30px;
			line-height:30px;
		}
		.content p input{
			height:26px;
			width:180px;
			padding-left:10px;
			border:1px solid #dadada;
			border-radius:3px;
		}
		.content p span{
			margin-left:7px;
			display:inline-block;
			width:220px;
			float:right;						
		}
		.main{
			padding-top:25px;
		}
		
	</style>
	<body>	
		<div class='main'>
			<div class='content'>
				
			</div>			
		</div>
		<div style='height:50px;'></div>
		<div class='btnBox'>
			<button class='sure'>确认</button>
			<button class='cancel'>取消</button>
		</div>
		<script type="text/javascript" src="../js/jquery-1.12.4.js" ></script>	
		<script type="text/javascript" src="../layer-v2.4/layer/layer.js" ></script>	
		<script type="text/javascript" src="../js/common.js" ></script>
		<script>
			
		//______________________________________________________________________________渲染页面
		drawPage()
		function drawPage(){
			var changeType = getHref().type;
			if(changeType=="M"){
				var idArr = (getHref().idArr).split(",");
				var str="";						
				str+="<p>座位数<span><input class='seatCount' type='text'/></span></p>"+
					 "<p>票损<span><input class='ticketLoss' type='text'/></span></p>"+
					 "<p>票损率<span><input class='ticketLossRate' type='text'/></span></p>"+
					 "<p>出票率<span><input class='ticketRate' type='text'></span></p>"+
					 "<p>结算单价<span><input class='price' type='text'></span></p>"+
					 "<p>报价单价<span><input class='viewAdultPrice' type='text'></span></p>"+	
					 "<p>结算儿童价<span><input class='childPrice' type='text' ></span></p>"+
					 "<p>报价儿童价<span><input class='viewChildPrice' type='text' ></span></p>"+									 
					 "<p>结算婴儿价<span><input class='infantPrice' type='text' ></span></p>"+
					 "<p>报价婴儿价<span><input class='viewInfantPrice' type='text' ></span></p>"+					
					 "<p>备注<span><input class='remark' type='text'/></span></p>"		
			}else if(changeType=="S"){
				var cutSeatOrderMessage = parent.cutSeatOrderMessage;
				var str="";						
				str+="<p>订单号<span class='id'>"+cutSeatOrderMessage.orderId+"</span></p>"+
					 "<p>座位数<span><input value="+cutSeatOrderMessage.passengerTotal+" class='seatCount' type='text'/></span></p>"+
					 "<p>票损<span><input value="+cutSeatOrderMessage.ticketLoss+" class='ticketLoss' type='text'/></span></p>"+
					 "<p>票损率<span><input value="+cutSeatOrderMessage.ticketLossRate+" class='ticketLossRate' type='text'/></span></p>"+
					 "<p>出票率<span><input class='ticketRate' type='text' value="+cutSeatOrderMessage.ticketRate+"></span></p>"+
					 "<p>结算单价<span><input class='price' type='text' value="+cutSeatOrderMessage.price+"></span></p>"+
					 "<p>报价单价<span><input class='viewAdultPrice' type='text' value="+commomFun.toEmptyString(cutSeatOrderMessage.viewAdultPrice)+"></span></p>"+	
					 "<p>结算儿童价<span><input class='childPrice' type='text' value="+cutSeatOrderMessage.childPrice+"></span></p>"+
					 "<p>报价儿童价<span><input class='viewChildPrice' type='text' value="+commomFun.toEmptyString(cutSeatOrderMessage.viewChildPrice)+"></span></p>"+									 
					 "<p>结算婴儿价<span><input class='infantPrice' type='text' value="+cutSeatOrderMessage.infantPrice+"></span></p>"+
					 "<p>报价婴儿价<span><input class='viewInfantPrice' type='text' value="+commomFun.toEmptyString(cutSeatOrderMessage.viewInfantPrice)+"></span></p>"+					
					 "<p>备注<span><input class='remark' type='text'/></span></p>"		
			}							
			$(".content").append(str) 
		}
		//_______________________________________________________________________________
				function commonFun(json,postData){
					json.seatCount=$(".seatCount").val();
					json.price=$(".price").val();
					json.viewAdultPrice=$(".viewAdultPrice").val();
					json.ticketLoss=$(".ticketLoss").val();
					json.ticketLossRate=$(".ticketLossRate").val();
					json.ticketRate=$(".ticketRate").val();
					json.childPrice=$(".childPrice").val();
					json.viewChildPrice=$(".viewChildPrice").val();
					json.infantPrice=$(".infantPrice").val();
					json.viewInfantPrice=$(".viewInfantPrice").val();
					json.remark=$(".remark").val();
					//校验				
					inputCheckoutFun.seatCount.normal(json.seatCount,"座位数","为正整数!");//座位数校验				
					inputCheckoutFun.price.normal(json.ticketLoss,"票损","为数字,最多保留两位小数!");//票损校验
					inputCheckoutFun.rate.normal(json.ticketLossRate,"票损率","不大于100,最多保留两位小数!");//票损率校验
					inputCheckoutFun.rate.normal(json.ticketRate,"出票率","不大于100,最多保留两位小数!");//出票率校验
					inputCheckoutFun.price.normal(json.price,"结算单价","为数字，最多保留两位小数!");//结算单价校验
					inputCheckoutFun.price.normal(json.viewAdultPrice,"报价单价","为数字，最多保留两位小数!");//报价单价校验
					inputCheckoutFun.price.normal(json.childPrice,"结算儿童价","为数字，最多保留两位小数!");//结算婴儿价校验
					inputCheckoutFun.price.normal(json.viewChildPrice,"报价儿童价","为数字，最多保留两位小数!");//报价婴儿价校验
					inputCheckoutFun.price.normal(json.infantPrice,"结算婴儿价","为数字，最多保留两位小数!");//结算婴儿价校验
					inputCheckoutFun.price.normal(json.viewInfantPrice,"报价婴儿价","为数字，最多保留两位小数!");//报价婴儿价校验
					inputCheckoutFun.Empty(json.remark,"备注","不能为空!");//备注校验
					
					if(Number(json.ticketLossRate)>Number(json.ticketRate)){
						layer.msg("票损率不能大于出票率",{icon:2})
						throw "票损率不能大于出票率"; 
					}
					postData.push(json)
				}
		//______________________________________________________________________________确定
		$(".sure").click(function(){
			var changeType = getHref().type;
			var postData = [];
			if(changeType=="S"){
				var json={};
				json.id=$(".id").text();
				commonFun(json,postData);				
			}else if(changeType=="M"){
				var idArr = (getHref().idArr).split(",");
				for(var i=0;i<idArr.length;i++){
					var json={};
					json.id = idArr[i];
					commonFun(json,postData);
				}
			}			
			$.ajax({
				type:"post",
				url:"../order/seat/pm?temp="+Math.random(),
				contentType:'application/json;charset=utf-8',
				data:JSON.stringify(postData),
				async:true,
				success:function(data){
					data = JSON.parse(data)
					if(data.status=="1001"){
						layer.msg('更改订单成功', {icon: 1,time:1000},function(){
							var index = parent.layer.getFrameIndex(window.name);//获取弹窗索引
							parent.layer.close(index);//关闭弹窗
						});			
					}else{
						//失败的弹出框
						layer.confirm("更改订单失败"+data.message, {
							title:['更改订单失败','background-color:#00aa98;color:#fff'],
						   	btn: ['确定'] //按钮
						}, function(){
							layer.closeAll('dialog');
						});
					}
				},
				error:function(){
					alert("请检查您的网络连接，并重试");
				}
			});
			
			
		})
		
		
		//_______________________________________________________________________________取消
			$(".cancel").click(function(){
				closeWin()
			})
		
		</script>
	</body>
</html>
